//网络请求
import axios from 'axios';
import AppConfig from '@/constants/AppConfig.js';

const $axios = axios;

export default function() {
    var $app_config = AppConfig();
	var $base_url = $app_config.Base_Url;
	var $post_config = $app_config.POST_Cfg;
	// 获取
    var $url_get_nations = $base_url + "/admin/nation/v1/getNations";
    // 编辑
    var $url_edit = $base_url + "/admin/nation/v1/edit";
    // 编辑顺序
    var $url_editSort = $base_url + "/admin/nation/v1/editSort";
    // 启用
    var $url_enable = $base_url + '/admin/nation/v1/enable';
    // 禁用
    var $url_disable = $base_url + '/admin/nation/v1/disable';
    //删除
    var $url_delete = $base_url + '/admin/nation/v1/delete';

    return {
		getNations: function(type) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_get_nations, {
					type: type
				}, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
        },
        edit: function(params) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_edit, {
                    lid: params.lid,
                    name: params.name
                }, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
        },
        enable: function(lid) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_enable, {
                    lid: lid
                }, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
        },
        disable: function(lid) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_disable, {
                    lid: lid
                }, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		},
		delete: function(lid) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_delete, {
                    lid: lid
                }, $post_config)
					.then(function(response) {
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		},
		editSort: function(sorts) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_editSort, {
                    sorts: sorts,
                }, $post_config)
					.then(function(response) {
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		}
    }
}